/*************************************************************
  Cocus Core - A simple PIC16 core emulator for PIC18
  
  version 2.0 by Santiago H. (santiagohssl@gmail.com)

  UNDER GNU LGPL

  file: service_usart.h
*************************************************************/

#include <p18cxxx.h>
#include "vmcore.h"

#ifndef VM_SERVICE_USART
#define VM_SERVICE_USART


#define CORE_USART_TXREG			0x19
#define CORE_USART_RCREG			0x1A

#define CORE_USART_PIR1				0x0C
#define CORE_USART_BIT_TXIF			0x04
#define CORE_USART_BIT_RCIF			0x05

#define CORE_USART_PIE1				0x8C
#define CORE_USART_BIT_RCIE			0x05
#define CORE_USART_BIT_TXIE			0x04

#define CORE_USART_TXSTA			0x98
#define CORE_USART_BIT_TXEN			0x05
#define CORE_USART_BIT_TRMT			0x01

#define CORE_USART_RCSTA			0x18
#define CORE_USART_BIT_SPEN			0x07
#define CORE_USART_BIT_SREN			0x05
#define CORE_USART_BIT_CREN			0x04


#define CORE_USART_DEFAULT_TXSTA	0x02
#define CORE_USART_DEFAULT_RCSTA	0x00


void vm_services_usart_init(void *dev);
void vm_services_usart(void *dev, vm_opcode *opcode);
char vm_services_usart_read_hook(void *dev, int pos, char * data);
char vm_services_usart_write_hook(void *dev, int pos, char * data);
void vm_services_usart_rx(void *dev, char data);


/*
***************** ATTENTION **************
The user should define this function in the
main file. It works as event-callback.
***************** ATTENTION **************
*/
void vm_services_usart_callback_tx(void *dev, char data);







#endif
